using DslModeling = global::Microsoft.VisualStudio.Modeling;
using DslDesign = global::Microsoft.VisualStudio.Modeling.Design;
using DslDiagrams = global::Microsoft.VisualStudio.Modeling.Diagrams;


namespace Guava.ChannelTransformations
{
    public partial class Flow
    {

        protected override bool CanMerge(DslModeling::ProtoElementBase rootElement, DslModeling::ElementGroupPrototype elementGroupPrototype)
        {
            if (elementGroupPrototype == null) throw new global::System.ArgumentNullException("elementGroupPrototype");

            if (rootElement != null)
            {
                DslModeling::DomainClassInfo rootElementDomainInfo = this.Partition.DomainDataDirectory.GetDomainClass(rootElement.DomainClassId);

                if (rootElementDomainInfo.IsDerivedFrom(global::Guava.ChannelTransformations.Operators.DomainClassId))
                {
                    return true;
                }
            }
            return base.CanMerge(rootElement, elementGroupPrototype);
        }
        protected override void MergeRelate(DslModeling::ModelElement sourceElement, DslModeling::ElementGroup elementGroup)
        {
            // In general, sourceElement is allowed to be null, meaning that the elementGroup must be parsed for special cases.
            // However this is not supported in generated code.  Use double-deriving on this class and then override MergeRelate completely if you 
            // need to support this case.
            if (sourceElement == null) throw new global::System.ArgumentNullException("sourceElement");


            global::Guava.ChannelTransformations.Operators sourceOperators1 = sourceElement as global::Guava.ChannelTransformations.Operators;
            if (sourceOperators1 != null)
            {
                // Create link for path ChannelHasOperator.Operator
                //this.Operator.Add(sourceOperators1);
                this.FlowFrom.Channel.Operator.Add(sourceOperators1);

                //this.FlowTo = sourceOperators1;

                Operators opSource = this.FlowFrom;
                Operators opTarget = this.FlowTo;

                opSource.FlowTo.Clear();
                opTarget.FlowFrom = null;

                sourceOperators1.FlowTo.Add(opTarget);
                sourceOperators1.FlowFrom = opSource;



                return;
            }
            // Fall through to base class if this class hasn't handled the merge.
            base.MergeRelate(sourceElement, elementGroup);
        }
        protected override void MergeDisconnect(DslModeling::ModelElement sourceElement)
        {

        }
    }
}
